package core;

/**
 * Client program requesting current date from server.
 *
 * Figure 3.27
 *
 * @author Gagne, Galvin, Silberschatz Operating System Concepts with Java -
 * Eighth Edition Copyright John Wiley & Sons - 2010.
 */
import java.net.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Client {
    private InputStream in = null;
    private BufferedReader bin = null;
    private Socket sock = null;

    public Client(String host, int port) {
        try {
            sock = new Socket(host, port);
            in = sock.getInputStream();
            bin = new BufferedReader(new InputStreamReader(in));

            String line;
            while ((line = bin.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException ioe) {
            System.err.println(ioe);
        } finally {
            try {
                sock.close();
            } catch (IOException ex) {
                Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
